package com.itshidu.jiaowu.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.itshidu.jiaowu.dao.*;
import com.itshidu.jiaowu.entity.Major;
import com.itshidu.jiaowu.entity.User;
import com.itshidu.jiaowu.service.ClassesService;
import com.itshidu.jiaowu.service.TeacherService;
import com.itshidu.jiaowu.util.Result;
import com.itshidu.web.tools.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author XiaZengming123
 * @since 2019-07-08
 */
@Controller
public class ClassesAction {
    @Autowired UserMapper userMapper;
    @Autowired TeacherMapper teacherMapper;
    @Autowired MajorMapper majorMapper;
    @Autowired TeacherService teacherservice;
    @Autowired ClassesService classesService;
    @Autowired StudentClassesMapper studentClassesMapper;
    @Autowired ClassesMapper classesMapper;

    //班级添加板块中授课老师、班长、班主任、班级的点击查询
    @ResponseBody
    @RequestMapping("/hello")
    public Object hello(String keyword) {

        EntityWrapper<User> wrapper = new EntityWrapper<>();
        wrapper.or().like("username", keyword);
        wrapper.or().like("email", keyword);
        wrapper.or().like("phone", keyword);
        List list=userMapper.selectList(wrapper);
//        System.out.println(list);

        return R.of().put("value",list);
    }

    //班级添加板块中专业的点击查询
    @ResponseBody
    @RequestMapping("/major")
    public Object major(String keyword) {

        EntityWrapper<Major> majorwrapper = new EntityWrapper<>();
        majorwrapper.like("NAME", keyword);
        List list= majorMapper.selectList(majorwrapper);
//        System.out.println(list);

        return R.of().put("value",list);
    }

    //班级添加
    @ResponseBody
    @RequestMapping("/admin/class/save")
    public Result major(Long teacher,Long student,Long banteacher,Long maior,String classname,int stage,String start_date,String nd_date) {
        Result r=classesService.TeacherSave(teacher,student,banteacher,maior,classname,stage,start_date,nd_date);
        return r;
    }
    //班次管理
    @ResponseBody
    @RequestMapping("/admin/banci/show")
    public Result SelectClass(int page, int limit) {

        return classesService.list(page, limit);
    }

    //某班次学生管理的 添加 按钮
    @ResponseBody
    @RequestMapping("/all{banciId}")
    public Object Class_add_button(@PathVariable Long banciId, ModelAndView mv, HttpServletResponse response) {

        List<String> allClassName =classesMapper.SelectAll();                  //查询所有班次名
        mv.addObject("allname",allClassName);
        mv.setViewName("ShowAllStudent");
        return mv;
    }

    //某个班级的 学生管理 页面中搜索框
    @ResponseBody
    @RequestMapping("/api/table/search")
    public Result SelectByClassName(int page,int limit,String key1) {

        return classesService.selectAllByClassName(page,limit,key1);
    }

    //给某个班级添加学生
    @ResponseBody
    @RequestMapping("/admin/addId")
    public Result Class_add_student(@RequestParam("idArray[]")Long[]arr, HttpServletRequest request) {

        return classesService.ClassAddStudent(arr,request);
    }


    }

